From: Julian Sparber Date: Fri, 26 Jan 2024 13:54:04 +0000 (+0100) Subject: messageList: Add property to display the timestamp of a message X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~281^2~2^2~68 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=f8fce24d5c6afe3088cc4ce6ffba8df9cb7e7e20;p=gnome-shell.git messageList: Add property to display the timestamp of a message This also adds the needed actor to display the timestamp. Part-of: --- diff --git a/js/ui/messageList.js b/js/ui/messageList.js index 5797c6dde..ab0f440da 100644 --- a/js/ui/messageList.js +++ b/js/ui/messageList.js @@ -12,6 +12,7 @@ import * as Main from './main.js'; import * as MessageTray from './messageTray.js'; import * as Util from '../misc/util.js'; +import {formatTimeSpan} from '../misc/dateUtils.js'; const MESSAGE_ANIMATION_TIME = 100; @@ -305,6 +306,46 @@ const LabelExpanderLayout = GObject.registerClass({ } }); +const TimeLabel = GObject.registerClass( +class TimeLabel extends St.Label { + _init() { + super._init({ + style_class: 'event-time', + x_expand: true, + y_expand: true, + x_align: Clutter.ActorAlign.START, + y_align: Clutter.ActorAlign.END, + visible: false, + }); + } + + get datetime() { + return this._datetime; + } + + set datetime(datetime) { + if (this._datetime?.equal(datetime)) + return; + + this._datetime = datetime; + + this.visible = !!this._datetime; + + if (this.mapped) + this._updateText(); + } + + _updateText() { + if (this._datetime) + this.text = formatTimeSpan(this._datetime); + } + + vfunc_map() { + this._updateText(); + + super.vfunc_map(); + } +}); export const Message = GObject.registerClass({ Signals: { @@ -408,6 +449,20 @@ export const Message = GObject.registerClass({ this._iconBin.visible = actor != null; } + get datetime() { + if (this._secondaryBin.child instanceof TimeLabel) + return this._secondaryBin.child.datetime; + else + return null; + } + + set datetime(datetime) { + if (!(this._secondaryBin.child instanceof TimeLabel)) + this._secondaryBin.child = new TimeLabel(); + + this._secondaryBin.child.set({datetime}); + } + setSecondaryActor(actor) { this._secondaryBin.child = actor; }